package com.momalib.ning2_nocode.services.impl;

import com.momalib.ning2_nocode.beans.*;
import com.momalib.ning2_nocode.services.SourceParseService;
import com.momalib.ning2_nocode.services.TemplateParseService;
import com.momalib.ning2_nocode.utils.CommonFileUtil;
import com.momalib.ning2_nocode.utils.NncConfUtil;
import com.momalib.ning2_nocode.utils.YamlUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

@Service
public class TemplateParseServiceImpl implements TemplateParseService {

    @Autowired
    NncConfUtil nncConfUtil;

    @Autowired
    SourceParseService sourceParseService;

    @Override
    public NncTmplConfig analyseTmplConfig(String rootPath) {
        String defaultProjectConfigName = "tmpl.yaml";
//        System.out.println(rootPath);
        File rootConfigFile = new File(rootPath + "/" + defaultProjectConfigName);
        if (!rootConfigFile.exists()) {
            System.out.println("文件不存在1");
            return null;
        }

        return YamlUtil.parseConfig(rootConfigFile, new NncTmplConfig());
    }

    @Override
    public void handleTmplBuild(String tmplRootPath, NncTmplConfig tmplConfig) {
        String origin = tmplConfig.getOrigin();
        if ("source".equals(origin)) {
            sourceParseService.handleSourceBuild(tmplRootPath, tmplConfig.getSource());
        }
    }
}
